package com.utopia.keyvalue.store.impl.disk;

import junit.framework.TestCase;

import org.apache.commons.lang.RandomStringUtils;

import com.utopia.keyvalue.store.Storage;

/**
 *@author yanjiaqiang
 *@date 2011-3-22
 *@version $Id: PerformanceTest.java 5 2011-03-22 09:23:42Z JiaqiangYan@gmail.com $ 
 */
public class PerformanceTest extends TestCase {

	public void testPerformance() {
		int times = 1000;
		int unit = 10000;
		int i = 0;
		byte[] value = RandomStringUtils.random(1024).getBytes();
		Storage storage = newStorage();
		long start = System.currentTimeMillis();
		while (i < unit * times) {
			storage.put(i + "", value);
			i++;
		}
		long end = System.currentTimeMillis();

		double speedPer10K = unit * times * 1000 / (end - start);
		System.out.println("put : " + speedPer10K + "/s");

		i = 0;
		start = System.currentTimeMillis();
		while (i < unit * times) {
			byte[] bs = storage.get(i + "");
			i++;
		}
		end = System.currentTimeMillis();

		speedPer10K = unit * times * 1000 / (end - start);
		System.out.println("get :" + speedPer10K + "/s");
		storage.close();
	}



	private Storage newStorage() {
		return new DiskHashStorage();
	}
}
